/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
 * Description: atrace接口
 * Author: wuhaoyu
 * Create: 2025-02-10
 */

#ifndef HCCL_SRC_DlTraceFunction_H
#define HCCL_SRC_DlTraceFunction_H

#include <functional>
#include <mutex>
#include <hccl/hccl_types.h>
#include "base.h"
#include "hccl/base.h"
#ifdef CCL_KERNEL_AICPU
#include "utrace_api.h"
#else
#include "atrace_api.h"
#endif

namespace hccl {
class DlTraceFunction {
public:
    virtual ~DlTraceFunction();
    static DlTraceFunction &GetInstance();
    HcclResult DlTraceFunctionInit();
#ifndef CCL_KERNEL_AICPU
    std::function<void(TraHandle handle)> dlAtraceDestroy{};
    std::function<HcclResult(TraHandle handle, const void *buffer, u32 bufSize)> dlAtraceSubmit{};
    std::function<TraHandle(int tracerType, const char *objName, const TraceAttr *attr)> dlAtraceCreateWithAttr{};
#else
    std::function<void(TraHandle handle)> dlUtraceDestroy{};
    std::function<HcclResult(TraHandle handle, const void *buffer, u32 bufSize)> dlUtraceSubmit{};
    std::function<TraHandle(int tracerType, const char *objName, const TraceAttr *attr)> dlUtraceCreateWithAttr{};
    std::function<TraStatus(const TraceGlobalAttr *attr)> dlUtraceSetGlobalAttr{};
    std::function<TraStatus(TracerType tracerType, bool syncFlag)> dlUtraceSave{};
#endif
private:
    void *handle_;
    std::mutex handleMutex_;
    DlTraceFunction(const DlTraceFunction&);
    DlTraceFunction &operator=(const DlTraceFunction&);
    DlTraceFunction();
    HcclResult DlTraceFunctionInterInit();
};
}  // namespace hccl
#endif